﻿namespace Hardcodet.Wpf.TaskbarNotification
{
    using System;
    using System.Drawing;
    using System.Runtime.CompilerServices;
    using System.Windows;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Resources;

    internal static class Util
    {
        public static readonly object a = new object();
        private static readonly bool b = ((bool) DependencyPropertyDescriptor.FromProperty(DesignerProperties.IsInDesignModeProperty, typeof(FrameworkElement)).Metadata.DefaultValue);

        public static Window a()
        {
            return new Window { Width = 0.0, Height = 0.0, ShowInTaskbar = false, WindowStyle = WindowStyle.None, AllowsTransparency = true, Opacity = 0.0 };
        }

        public static l a(this BalloonIcon A_0)
        {
            switch (A_0)
            {
                case BalloonIcon.None:
                    return l.a;

                case BalloonIcon.Info:
                    return l.b;

                case BalloonIcon.Warning:
                    return l.c;

                case BalloonIcon.Error:
                    return l.d;
            }
            throw new ArgumentOutOfRangeException("icon");
        }

        public static bool a(this FrameworkElement A_0)
        {
            if (A_0 == null)
            {
                throw new ArgumentNullException("element");
            }
            return (A_0.GetBindingExpression(FrameworkElement.DataContextProperty) != null);
        }

        public static Icon a(this ImageSource A_0)
        {
            if (A_0 == null)
            {
                return null;
            }
            Uri uriResource = new Uri(A_0.ToString());
            StreamResourceInfo resourceStream = Application.GetResourceStream(uriResource);
            if (resourceStream == null)
            {
                string format = "The supplied image source '{0}' could not be resolved.";
                throw new ArgumentException(string.Format(format, A_0));
            }
            return new Icon(resourceStream.Stream);
        }

        public static bool a(ref f A_0, q A_1)
        {
            return a(ref A_0, A_1, A_0.d);
        }

        public static bool a(this c A_0, PopupActivationMode A_1)
        {
            switch (A_1)
            {
                case PopupActivationMode.LeftClick:
                    return (A_0 == c.e);

                case PopupActivationMode.RightClick:
                    return (A_0 == c.d);

                case PopupActivationMode.DoubleClick:
                    return A_0.Is<c>(new c[] { c.h });

                case PopupActivationMode.LeftOrRightClick:
                    return A_0.Is<c>(new c[] { c.e, c.d });

                case PopupActivationMode.LeftOrDoubleClick:
                    return A_0.Is<c>(new c[] { c.e, c.h });

                case PopupActivationMode.MiddleClick:
                    return (A_0 == c.g);

                case PopupActivationMode.All:
                    return (A_0 != c.a);
            }
            throw new ArgumentOutOfRangeException("activationMode");
        }

        public static bool a(ref f A_0, q A_1, g A_2)
        {
            if (b())
            {
                return true;
            }
            A_0.d = A_2;
            lock (a)
            {
                return o.Shell_NotifyIcon(A_1, ref A_0);
            }
        }

        public static void a(this ICommand A_0, object A_1, IInputElement A_2)
        {
            if (A_0 != null)
            {
                RoutedCommand command = A_0 as RoutedCommand;
                if (command != null)
                {
                    if (command.CanExecute(A_1, A_2))
                    {
                        command.Execute(A_1, A_2);
                    }
                }
                else if (A_0.CanExecute(A_1))
                {
                    A_0.Execute(A_1);
                }
            }
        }

        public static bool Is<T>(this T value, params T[] candidates)
        {
            if (candidates != null)
            {
                foreach (T local in candidates)
                {
                    if (value.Equals(local))
                    {
                        return true;
                    }
                }
            }
            return false;
        }

        public static bool IsDesignMode
        {
            get
            {
                return b;
            }
        }
    }
}

